import { CSSProperties } from 'react'
import classNames from 'classnames'
import { Pagination } from 'antd'

import { getDefaultPaginationProps } from '@/utils/pagination'
import styles from './styles.module.less'

export interface IUnifiedPaginationProps {
  current: number
  pageSize: number
  total: number | undefined
  onChange: (page: number, pageSize: number) => void
  style?: CSSProperties
  className?: string
}

/** 统一分页器 */
export const UnifiedPagination = Object.assign(
  ({ current, pageSize, total, onChange, style, className }: IUnifiedPaginationProps) => {
    return (
      <div style={style} className={classNames(styles.UnifiedPagination, className)}>
        <Pagination
          {...getDefaultPaginationProps(total ?? 0)}
          current={current}
          pageSize={pageSize}
          onChange={onChange}
        />
      </div>
    )
  },
  {
    /** 用于类型约束 */
    defineProps: (props: IUnifiedPaginationProps): IUnifiedPaginationProps => props,
  },
)
